home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 2811 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.2 KB  |  41 lines

  1. Newsgroups: comp.lang.c++
  2. Path: cdf.toronto.edu!news
  3. From: Paul Dowman <a209dowm@cdf.utoronto.ca>
  4. Subject: Re: overloaded operator question
  5. Content-Type: text/plain; charset=us-ascii
  6. Message-ID: <DLG020.DzL@cdf.toronto.edu>
  7. Sender: news@cdf.toronto.edu (Usenet News)
  8. Nntp-Posting-Host: lysander
  9. Content-Transfer-Encoding: 7bit
  10. Organization: Computing Disciplines Facility, University of Toronto
  11. References: <4dmin1$160@noc2.drexel.edu> <4domv0$hfk@charnel.ecst.csuchico.edu>
  12. Mime-Version: 1.0
  13. Date: Fri, 19 Jan 1996 19:13:10 GMT
  14. X-Mailer: Mozilla 1.1N (X11; I; SunOS 5.3 sun4c)
  15. X-Url: news:4domv0$hfk@charnel.ecst.csuchico.edu
  16.  
  17. >Just to clean things up a bit, seeing as how you are not altering
  18. >either the left or right operand here, but instead returning a
  19. >new (temporary) matrix as the result  of the operation, your
  20. >method declaration should be:
  21. >
  22. >    Matrix Matrix::operator * (const Matrix & right) const;
  23.  
  24.  
  25.  
  26. why not declare the operator outside the object? eg: 
  27.  
  28. matrix operator * (matrix &matrix_a, matrix &matrix_b)
  29. {
  30.     // returns a third temp matrix object
  31. }
  32.  
  33. then when you use it:
  34. matrix_c = matrix_a * matrix_b;
  35.  
  36. This is how I have done it, following examples in the O'Reilly book "Practical
  37. C++ Programming" (I am learning it now)
  38.  
  39.  - Paul.
  40.  
  41.